package wodegua.d24_file_io;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class d17_IoBufferedTest {
    public static void main(String[] args) {
        // 目标:恢复出师表的顺序到新文件中。
        List<String> list = new ArrayList<>();
        try (
                BufferedReader bfr = new BufferedReader(new FileReader("helloworld-app/csb.txt"));
                BufferedWriter bfw = new BufferedWriter(new FileWriter("helloworld-app/csb_bak.txt"));
        ) {
            String line;
            while ((line = bfr.readLine()) != null) {
                list.add(line);
            }
            Collections.sort(list);
            for (String s : list) {
                bfw.write(s);
                bfw.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
